//demo gallery implemented as another express application
//'app mounting'

var express = require('express');
var app = module.exports = express();

// '/demo'
app.get('/', function (req, res, next) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    var links = '<a href="/demo/cube">Cube Demo</a><br/>' +
        '<a href="/demo/voxel">Voxel Demo</a><br/>' +
        '<a href="/demo/text">Text Demo</a><br/>' +
        '<a href="/demo/rpg">RPG Demo</a><br/>' +
        '<a href="/demo/flight">Flight Demo</a><br/>';
    res.end('demo gallery goes here!<br/><br/>' + links);
});


// /demo/cube
app.get('/cube', function(req, res, next) {
    res.render('demo', {
        title: 'Cube Demo',
        name: 'cube',
        scripts: ['lib/require.min.js', 'lib/three.min.js', 'lib/RequestAnimationFrame.js', 'lib/Stats.js',
                  'engine/doll.js', 'engine/ui.js', 'engine/ui/text.js', 'engine/ui/selectable.js',
                  'engine/draw.js', 'engine/fetch.js', 'engine/audio.js']
    });
});

// /demo/cam
app.get('/cam', function(req, res, next) {
    res.render('demo', {
        title: 'Cam Demo',
        name: 'cam',
        scripts: ['lib/three.min.js', 'lib/RequestAnimationFrame.js', 'lib/Stats.js']
    });
});

// /demo/voxel
app.get('/voxel', function(req, res, next) {
    res.render('demo', {
        title: 'Voxel Demo',
        name: 'voxel',
        scripts: ['lib/three.js', 'lib/RequestAnimationFrame.js', 'lib/Stats.js']
    });
});

// /demo/rpg
app.get('/rpg', function(req, res, next) {
    res.render('demo', {
        title: 'RPG Demo',
        name: 'rpg',
        scripts: ['lib/three.js', 'lib/RequestAnimationFrame.js', 'lib/Stats.js']
    });
});

// /demo/flight
app.get('/flight', function(req, res, next) {
    res.render('demo', {
        title: 'Flight Demo',
        name: 'flight',
        scripts: ['lib/three.js', 'lib/RequestAnimationFrame.js', 'lib/Stats.js']
    });
});


// /demo/text
app.get('/text', function(req, res, next) {
    res.render('demo', {
        title: 'Text Demo',
        name: 'text',
        scripts: ['lib/three.js', 'lib/RequestAnimationFrame.js', 'lib/Stats.js']
    });
});

// '/demo/:name'
app.get('/:name', function(req, res, next) {
    res.writeHead(404);
    res.end('demo ' + req.params.name + ' not found!');
});



